//
//  AirAttributedView.m
//  YSSmartHome
//
//  Created by yanghao on 2017/3/13.
//  Copyright © 2017年 yahaong. All rights reserved.
//

#import "AirAttributedView.h"
#import "YHMarcros.h"
#import "ZTAirMonitorDevice.h"

@interface AirAttributedView ()
@property (nullable, nonatomic, strong) UIImageView* mImgSplitV;
@property (nullable, nonatomic, strong) UIImageView* mImgSplitH;
@property (nullable, nonatomic, strong) UIButton* mBtnFormaldehyde;
@property (nullable, nonatomic, strong) UILabel*  mLblFormaldehyde;
@property (nullable, nonatomic, strong) UIButton* mBtnTemperature;
@property (nullable, nonatomic, strong) UILabel*  mLblTemperature;
@property (nullable, nonatomic, strong) UIButton* mBtnHumidity;
@property (nullable, nonatomic, strong) UILabel*  mLblHumidity;
@property (nullable, nonatomic, strong) UIButton* mBtnIllumination;
@property (nullable, nonatomic, strong) UILabel*  mLblIllumination;

@end
@implementation AirAttributedView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.mImgSplitH];
    [self addSubview:self.mImgSplitV];
    [self addSubview:self.mLblFormaldehyde];
    [self addSubview:self.mBtnFormaldehyde];
    [self addSubview:self.mLblTemperature];
    [self addSubview:self.mBtnTemperature];
    [self addSubview:self.mLblHumidity];
    [self addSubview:self.mBtnHumidity];
    [self addSubview:self.mBtnIllumination];
    [self addSubview:self.mLblIllumination];
    [self layoutPageSubViews];
}
- (void)layoutPageSubViews
{
    [self.mImgSplitH mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.height.equalTo(kIphoneSize_Height(4));
        make.width.equalTo(kIphoneSize_Widith(345));
    }];
    [self.mImgSplitV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.equalTo(kIphoneSize_Height(4));
        make.height.equalTo(kIphoneSize_Widith(219));
    }];
    [self.mLblFormaldehyde mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.mImgSplitH).offset(kIphoneSize_Height(50));
        make.bottom.equalTo(self.mImgSplitH.top).offset(kIphoneSize_Height(-15));
    }];
    [self.mBtnFormaldehyde mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mLblFormaldehyde.top).offset(kIphoneSize_Height(-20));
        make.leading.equalTo(self.mImgSplitH).offset(kIphoneSize_Widith(20));
    }];
    [self.mLblTemperature mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mImgSplitH.top).offset(kIphoneSize_Height(-15));
        make.leading.equalTo(self.mImgSplitV.leading).offset(50);
    }];
    [self.mBtnTemperature mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mLblTemperature.top).offset(kIphoneSize_Height(-20));
        make.leading.equalTo(self.mImgSplitV.trailing).offset(20);
    }];
    [self.mBtnHumidity mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mImgSplitH.bottom).offset(kIphoneSize_Height(18));
        make.leading.equalTo(self.mImgSplitH).offset(kIphoneSize_Widith(20));
        
    }];
    [self.mLblHumidity mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mBtnHumidity.bottom).offset(kIphoneSize_Height(20));
        make.leading.equalTo(self.mImgSplitH).offset(kIphoneSize_Height(50));
    }];
    
    [self.mBtnIllumination mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mBtnHumidity);
        make.leading.equalTo(self.mImgSplitV).offset(kIphoneSize_Widith(20));
        
    }];
    [self.mLblIllumination mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mLblHumidity);
        make.leading.equalTo(self.mImgSplitV).offset(kIphoneSize_Height(50));
    }];
}

#pragma mark - getters and setters
- (void)setDevice:(ZTAirMonitorDevice *)device
{
    _device = device;
    self.mLblTemperature.text = [NSString stringWithFormat:@"%.1f ℃",device.tempValue / 10.0];
    
    self.mLblFormaldehyde.text = [NSString stringWithFormat:@"%.3f mg/m³",(device.formaldehydeValue / 1000.0 * 0.833)];
    self.mLblHumidity.text = [NSString stringWithFormat:@"%zd%% RH",device.humidityValue];
    self.mLblIllumination.text = [NSString stringWithFormat:@"%zd LX",device.illuminationValue];
}
- (UIImageView *)mImgSplitH
{
    if (!_mImgSplitH) {
        _mImgSplitH = [[UIImageView alloc]init];
        _mImgSplitH.image = [UIImage imageNamed:@"AirsplitH"];
    }
    return _mImgSplitH;
}

- (UIImageView *)mImgSplitV
{
    if (!_mImgSplitV) {
        _mImgSplitV = [[UIImageView alloc]init];
        _mImgSplitV.image = [UIImage imageNamed:@"AirsplitV"];
    }
    return _mImgSplitV;
}

//甲醛
- (UIButton *)mBtnFormaldehyde
{
    if (!_mBtnFormaldehyde) {
        _mBtnFormaldehyde = [UIButton  buttonWithType:UIButtonTypeCustom];
        [_mBtnFormaldehyde setImage:[UIImage imageNamed:@"air_formaldehyde_icon"] forState:UIControlStateNormal];
        [_mBtnFormaldehyde setTitle:@"甲醛" forState:UIControlStateNormal];
        [_mBtnFormaldehyde setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return _mBtnFormaldehyde;
}

- (UILabel *)mLblFormaldehyde
{
    if (!_mLblFormaldehyde) {
        _mLblFormaldehyde = [[UILabel alloc]init];
        _mLblFormaldehyde.textColor = [UIColor whiteColor];
    }
    return _mLblFormaldehyde;
}

//温度
- (UIButton *)mBtnTemperature
{
    if (!_mBtnTemperature) {
        _mBtnTemperature = [UIButton  buttonWithType:UIButtonTypeCustom];
        [_mBtnTemperature setImage:[UIImage imageNamed:@"air_temperature"] forState:UIControlStateNormal];
        [_mBtnTemperature setTitle:@"温度" forState:UIControlStateNormal];
        [_mBtnTemperature setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    }
    return _mBtnTemperature;
}

- (UILabel *)mLblTemperature
{
    if (!_mLblTemperature) {
        _mLblTemperature = [[UILabel alloc]init];
        _mLblTemperature.textColor = [UIColor whiteColor];
    }
    return _mLblTemperature ;
}
//湿度
- (UIButton *)mBtnHumidity
{
    if (!_mBtnHumidity) {
        _mBtnHumidity = [UIButton  buttonWithType:UIButtonTypeCustom];
        [_mBtnHumidity setImage:[UIImage imageNamed:@"air_humidity"] forState:UIControlStateNormal];
        [_mBtnHumidity setTitle:@"湿度" forState:UIControlStateNormal];
        [_mBtnHumidity setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return _mBtnHumidity;
}


- (UILabel *)mLblHumidity
{
    if (!_mLblHumidity) {
        _mLblHumidity = [[UILabel alloc]init];
        _mLblHumidity.textColor = [UIColor whiteColor];
    }
    return _mLblHumidity ;
}

//光照
- (UIButton *)mBtnIllumination
{
    if (!_mBtnIllumination) {
        _mBtnIllumination = [UIButton  buttonWithType:UIButtonTypeCustom];
        [_mBtnIllumination setImage:[UIImage imageNamed:@"air_illumination"] forState:UIControlStateNormal];
        [_mBtnIllumination setTitle:@"光照" forState:UIControlStateNormal];
        [_mBtnIllumination setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return _mBtnIllumination;
}

- (UILabel *)mLblIllumination
{
    if (!_mLblIllumination) {
        _mLblIllumination = [[UILabel alloc]init];
        _mLblIllumination.textColor = [UIColor whiteColor];
    }
    return _mLblIllumination ;
}


@end
